<template>
	<view class="upload-send">
		<up-button @click="handleClick" type="primary" :text="`上传${type==1?'寄件':type==2?'取件':'送达'}记录`"></up-button>
	</view>
	<up-popup :show="show" mode="center" @close="show = false" :safeAreaInsetBottom="false">
		<view class="popup">
			<image class="popup-top-bj" src="@/static/image/popup-bj.png"></image>
			<view class="popup-content">
				<view class="title">
					{{type==1?'寄件':type==2?'取件':'送达'}}记录
				</view>
				<view class="top">
					<view class="top-title">
						添加图片
					</view>
					<view class="top-desc">
						添加爱宠照片，最多三张
					</view>
				</view>
				<view class="upload-content">
					<view class="upload" v-for="(item, index) in 3" :key="index">
						<Upload :customStyle="2" :url="images[index]" @change="images[index] = $event" />
					</view>
				</view>
				<view class="popup-bottom">
					<view class="">
						<up-button @click="show = false" type="info" text="取消"></up-button>
					</view>
					<view class="">
						<up-button @click="handleSumbit" type="primary" text="确定"></up-button>
					</view>
				</view>
			</view>
		</view>
	</up-popup>
</template>

<script setup>
	import Upload from '@/components/Upload.vue'
	import {
		ref
	} from 'vue'
	import order from '@/api/order.js'
	import utils from '@/utils/util.js'
	const props = defineProps({
		type: {
			type: [Number, String],
			default: 1
		},
		id: {
			type: [Number, String],
			default: 0
		}
	})
	const show = ref(false)
	const images = ref([])
	const handleClick = () => {
		show.value = true
	}
	const emits = defineEmits(['change'])
	const handleSumbit = async () => {
		const { status, info, data } = await order[props.type == 1?'userUploadDispatchInfo': props.type == 2?'uploadPickupInfo':'uploadDeliveryInfo']({
			id: props.id,
			img: images.value
		})
		utils.toast(info)
		if(status == 1) {
			show.value = false
			emits('change')
		}
	}
</script>

<style lang="scss" scoped>
	.upload-send {
		margin-top: 40rpx;
	}

	.popup-content {
		.top {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.top-title {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #2C1F21;
			}

			.top-desc {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #989898;
			}
		}
		.upload-content {
			display: flex;
			justify-content: space-between;
			margin: 20rpx 0;
			.upload {
				width: calc((100vw - 102rpx - 80rpx) / 3);
				height: calc((100vw - 102rpx - 80rpx) / 3);
				
			}
		}
	}
</style>